<?php
/**
 * User: hjd-yao
 * Date: 2019/6/13
 * Time: 17:57
 */

namespace App\Models\Shop;


use App\Models\BaseModel;

class UserAddressModel extends BaseModel
{
    protected $table = 'shop_user_address';

    protected $primaryKey = 'id';

    public $dateFormat = 'U';

    public function user()
    {
        return $this->belongsTo('DC\UserCenter\Models\UserBaseModel','user_id','member_id');
    }

    public function getDefault($user_id)
    {
        $address = self::where('user_id',$user_id)->where('is_default',1)->first();
        if(!$address){
            $address = self::where('user_id',$user_id)->where('is_default',1)->first();
        }
        return $address;
    }
}